using System;
using UnityEngine;
using UnityEngine.UI;

namespace Hotfix
{
    public class LoginScirpt : BaseUI
    {
        public UnityEngine.GameObject login;

  

        public override void Start()
        {
            Toggle tog = UnityHelper.GetTheChildNodeComponetScripts<Toggle>(login, "Toggle");

            if (tog)
            {
                UnityHelper.GetTheChildNodeComponetScripts<InputField>(login, "UserName").text = PlayerPrefs.GetString("userName");
                UnityHelper.GetTheChildNodeComponetScripts<InputField>(login, "Password").text = PlayerPrefs.GetString("Pwd");
            }

            base.Start();
            Debug.Log(login);
            Button bu = login.transform.Find("LoginButton").GetComponent<Button>();
            bu.onClick.AddListener(() =>
            {
                UIManager.Instance.OpenUI("Home");
            });

            tog.onValueChanged.AddListener((b)=> {
                if (b)
                {
                    PlayerPrefs.SetString("userName", UnityHelper.GetTheChildNodeComponetScripts<InputField>(login, "UserName").text);
                    PlayerPrefs.SetString("Pwd", UnityHelper.GetTheChildNodeComponetScripts<InputField>(login, "Password").text);
                }
                else
                {
                    PlayerPrefs.DeleteKey("userName");
                    PlayerPrefs.DeleteKey("Pwd");
                }
            });
        }
        public override void Update()
        {
            base.Update();
        }
    }
}
